package com.wolffy.flink.source;

import com.wolffy.flink.bean.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;


public class CollectionDemo {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //  从元素读
        DataStreamSource<Integer> elementSource = env.fromElements(1,2,33);
        elementSource.print();
        // 从集合读
        DataStreamSource<Integer> listSource = env.fromCollection(Arrays.asList(1, 22, 3));
        listSource.print();

        // 从集合读
        List<WaterSensor> waterSensors = Arrays.asList(
                new WaterSensor("s1", 1L, 1),
                new WaterSensor("s1", 2L, 1),
                new WaterSensor("s1", 3L, 1)
        );
        DataStreamSource<WaterSensor> waterSensorDS = env.fromCollection(waterSensors);
        waterSensorDS.print();

        env.execute();

    }
}
